package com.logansoft.zhxypkoa.validators;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.logansoft.zhxypkoa.domain.sys.Dataset;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class DatasetValidator {

	@Component("beforeCreateDatasetValidator")
	class  DatasetBeforeCreateValidator implements Validator {

		@Override
		public boolean supports(Class<?> clazz) {
			// TODO Auto-generated method stub
			log.debug("clazz: " + clazz.getCanonicalName() + ", " + clazz.getName() + ", " + clazz.getTypeName());
			log.debug("Dataset.class.equals(clazz): " + Dataset.class.equals(clazz));
			return Dataset.class.equals(clazz);
		}

		@Override
		public void validate(Object target, Errors errors) {
			// TODO Auto-generated method stub
			Dataset dataset = (Dataset) target;
			log.debug("dataset.getName() = " + dataset.getName());
			/*if (dataset.getName() == null || dataset.getName().equals("")) {
				errors.rejectValue("name", "name.empty", "名称不能为空");
			}*/
			ValidationUtils.rejectIfEmpty(errors, "name", "name.empty");
		}
		
	}
}
